﻿#include "PyFITKPhyscisPropUniform.h"
#include "FITKAcousticsPhysics.h"
#include "FITKAcousticsAbsPhysicsProp.h"
#include "FITKAcousticsAbsMaterial.h"
#include "FITKPhyscisPropertyUniform.h"

Acoustics::PyFITKPhyscisPropUniform::PyFITKPhyscisPropUniform(const QString & name) :
    Acoustics::PyFITKPhyscisPropBase(name)
{
}

bool Acoustics::PyFITKPhyscisPropUniform::setMaterial(const QString & material)
{
    if (!_phyProp)return false;

    Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
    if (phy == nullptr) return false;
    Acoustics::FITKAcousticsMaterialManager* matMgr = phy->getMaterialManager();
    if (matMgr == nullptr) return false;
    if (!matMgr->getDataByName(material))return false;
    //类型判断？

    int id = matMgr->getDataByName(material)->getDataObjectID();
    FITKPhyscisPropertyUniform *uniform = dynamic_cast<Acoustics::FITKPhyscisPropertyUniform*>(_phyProp);
    if (!uniform)return false;

    uniform->setMaterialID(id);
    return true;
}

bool Acoustics::PyFITKPhyscisPropUniform::setThickness(double thickness)
{
    if (!_phyProp|| thickness < 0)return false;

    FITKPhyscisPropertyUniform *uniform = dynamic_cast<Acoustics::FITKPhyscisPropertyUniform*>(_phyProp);
    if (!uniform)return false;

    uniform->setThickness(thickness);
    return true;
}

bool Acoustics::PyFITKPhyscisPropUniform::createPhyscisProp(const QString & name)
{
    if (name == "")return false;
    Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
    if (phy == nullptr) return false;
    Acoustics::FITKAcousticsPhysicsPropManager* propMgr = phy->getPhysicsPropManager();
    if (propMgr == nullptr) return false;
    if (propMgr->getDataByName(name))return false;

    FITKPhyscisPropertyUniform *uniform = new FITKPhyscisPropertyUniform();
    uniform->setDataObjectName(name);
    _phyProp = uniform;
    propMgr->appendDataObj(_phyProp);
    return true;
}
